package com.block.datapush.service.apipush.utils;

import cn.hutool.core.util.StrUtil;
import com.block.common.enums.BaseTypeInfoEnum;
import org.apache.logging.log4j.util.Base64Util;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;


/**
 * 81 大麦花花  回调
 */
public class DaEMaskApisUtil {

    //贷款期限
    public static String getLoanAmount(String loanAmount) {
        if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la001.getValue()) || StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la002.getValue())) {
            return "1万-5万";
        } else if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la003.getValue())) {
            return "5万-10万";
        } else if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la004.getValue())) {
            return "10万-20万";
        }
        return "20万以上";
    }



    //职业身份
    public static String getJob(String jbo) {
        if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz001.getValue())) {
            return "上班族";
        } else if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz002.getValue())) {
            return "私营企业主";
        } else if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz004.getValue())) {
            return "公务员-事业单位";
        }
        return "自由职业";
    }




    //芝麻
    public static String getZhima(String zhima) {
        if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm002.getValue())) {
            return "600以下";
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm003.getValue())) {
            return "600-649以内";
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm004.getValue())) {
            return "650-699以内";
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm005.getValue())) {
            return "700以上";
        }
        return "600以下";
    }

    //逾期
    public static String getYuqi(String yuqi) {
        if (StrUtil.equals(yuqi, BaseTypeInfoEnum.Yuqi.yq001.getValue())) {
            return "无逾期";
        }
        return "有逾期";
    }

    //房产
    public static String getHouse(String house) {
        if (StrUtil.equals(house, BaseTypeInfoEnum.House.hu001.getValue())) {
            return "无";
        }
        return "有";
    }
    //车产
    public static String getCar(String car) {
        if (StrUtil.equals(car, BaseTypeInfoEnum.Car.car001.getValue())) {
            return "无";
        }
        return "有";
    }

    //公积金
    public static String getGjj(String gjj) {
        if (StrUtil.equals(gjj, BaseTypeInfoEnum.Gjj.gjj001.getValue())) {
            return "无";
        }
        return "六个月以上";
    }

    public static String getShebao(String shebao) {
        if(StrUtil.equals(shebao,BaseTypeInfoEnum.Shebao.sb001.getValue())){
            return "无";
        }
        return "有";
    }

    public static String getHuabei(String huabei) {
        if(StrUtil.equals(huabei, BaseTypeInfoEnum.Huabei.hb001.getValue())) {
            return "无";
        }
        return "有";
    }

    public static String getBaitiao(String baitiao) {
        if(StrUtil.equals(baitiao,BaseTypeInfoEnum.Baitiao.bt001.getValue())) {
            return "无";
        }
        return "有";
    }


    private static final String cipherAlgorithm = "AES/CBC/PKCS5Padding";private static final String keyAlgorithm = "AES";
    public static String encryptAES(String data, String key) {
        try {

            byte[] keyBytes = getUTF8Bytes(key);
            if (keyBytes.length % 8 != 0 || keyBytes.length < 16 || keyBytes.length > 32) {
                throw new RuntimeException("AES密钥长度不合法");
            }

            SecretKeySpec secretKey = new SecretKeySpec(keyBytes, keyAlgorithm);
            IvParameterSpec params = new IvParameterSpec(key.getBytes());

            Cipher cipher = Cipher.getInstance(cipherAlgorithm);
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, params);

            byte[] plaintext = getUTF8Bytes(data);
            byte[] encrypted = cipher.doFinal(plaintext);

            return Base64.getEncoder().encodeToString(encrypted).trim();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private static byte[] getUTF8Bytes(String input) {
        return input.getBytes(StandardCharsets.UTF_8);
    }


    public static String getBaoxian(String baoxian) {
        if(StrUtil.equals(baoxian,BaseTypeInfoEnum.Baoxian.bx001.getValue())) {
            return "无";
        }
        return "有";
    }
}
